﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ASmile.Win
{
    static class Config
    {
        static Config()
        {
            Settings = ConfigHelper.GetAppSettings<AppSettings>();

            if (!Settings.IsRemoteLogin)
            {
                DB = ConfigHelper.GetConnectString<ConfigDB>();
                if (Settings.ConnStringEncryption)
                {
                    //TODO: 解密连接字符串
                    //DB.Core = 解密(DB.Core);
                    //DB.Core = 解密("")
                }
            }
        }

        /// <summary>
        /// 本地 appSetings
        /// </summary>
        public static AppSettings Settings { private set; get; }

        /// <summary>
        /// 数据库连接字符串
        /// </summary>
        public static ConfigDB DB { private set; get; }
    }

    /// <summary>
    /// 本地appSetings 
    /// </summary>
    public class AppSettings
    {
        /// <summary>
        /// 应用程序主题
        /// </summary>
        public string Caption { set; get; } = "XX管理系统";
        /// <summary>
        /// 是否远程登陆
        /// </summary>
        public bool IsRemoteLogin { set; get; } = false;
        /// <summary>
        /// 连接字符串加密
        /// </summary>
        public bool ConnStringEncryption { set; get; }
        /// <summary>
        /// 是否只允许运行一个实例
        /// </summary>
        public bool RunOnleOne { set; get; }
        /// <summary>
        /// 图标文件目录
        /// </summary>
        public string IconFolder { set; get; } = "Icon";
        /// <summary>
        /// Http服务地址
        /// </summary>
        public string ServerUrl { set; get; }
        /// <summary>
        /// 客户端Id
        /// </summary>
        public string ClientId { set; get; } = "{C511BA45-BEF1-4CCD-B59A-9FA903BA1E0A}";

        /// <summary>
        /// Token header 名
        /// </summary>
        public string TokenName { set; get; } = "TOKEN";
        /// <summary>
        /// HTTP请求超时间隔，单位秒，默认:60
        /// </summary>
        public int TimeOutInterval { set; get; } = 60;
        /// <summary>
        /// 刷新Token URL,默认：api/ApiUser/RefreshToken
        /// </summary>
        public string RefreshTokenUrl { set; get; } = "api/ASmile/RefreshToken";
        /// <summary>
        /// 刷新token分钟（也用于保持连接）,默认为 2 分钟
        /// </summary>
        public int RefreshTokenMinutes { set; get; } = 2;
        ///// <summary>
        ///// 用于客户端PC的标识
        ///// </summary>
        //public string ClientSign { set; get; }
        /// <summary>
        /// 窗体默认图标
        /// </summary>
        public string FormIcon { set; get; } = "ASmile.ico";
        /// <summary>
        /// 主窗体的背景图片
        /// </summary>
        public string MainBackImgImage { set; get; }
        /// <summary>
        /// 更新文件路径
        /// </summary>
        public string UpdateFilePath { set; get; }
        /// <summary>
        /// 在线更新url
        /// </summary>
        public string OnlineUpdateUrl { get; set; }
        /// <summary>
        /// 默认分页大小
        /// </summary>
        public int DefaultPageSize { set; get; } = 50;
    }

    /// <summary>
    /// 数据库连接字符串配置
    /// </summary>
    public class ConfigDB
    {
        public string Core { set; get; }
    }
}
